package com.purchase.ml.resource.dealer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.purchase.ml.annotations.OperLog;
import com.purchase.ml.bean.base.ApiRestResult;
import com.purchase.ml.bean.req.dealer.DealerProdEditDto;
import com.purchase.ml.bean.req.dealer.DealerProdQueryDto;
import com.purchase.ml.bean.res.prod.SysProdRes;
import com.purchase.ml.consts.PermissionsConst;
import com.purchase.ml.service.prod.SysProdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author :zxm
 * @date :2021/3/9 16:33
 * @description :some description
 **/
@RestController
@RequestMapping("/dealer_product")
@Slf4j
@Api(tags = "经销商产品")
public class DealerProdResource {

    @Autowired
    private SysProdService sysProdService;

    @PostMapping("/query")
    @ApiOperation("分页查询主经销商产品")
    @RequiresPermissions(PermissionsConst.DEALER_PRODUCT_QUERY)
    public ApiRestResult dealerProdQuery(@RequestBody DealerProdQueryDto dealerProdQueryDto){
        IPage<SysProdRes> resIPage = sysProdService.dealerProdQuery(dealerProdQueryDto);
        return ApiRestResult.ok(resIPage);
    }

    @PostMapping("/edit")
    @ApiOperation("修改主经销商产品")
    @OperLog(operDesc = "editDealerProd", operModul = "dealer", operType = "edit")
    @RequiresPermissions(PermissionsConst.DEALER_PRODUCT_EDIT)
    public ApiRestResult editDealerProd(@RequestBody @Valid DealerProdEditDto dto){
        ApiRestResult result = sysProdService.editDealerProd(dto);
        return result;
    }
}
